﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ndo.Maths
{
    public class Integer16 : Integer<Integer16>
    {
        public Integer16()
            : this(1)
        { }
        [Ndo.Text.ParsingPattern(@"(\+|-)?\d+")]
        public Integer16(string text)
            : this(Int16.Parse(text))
        { }
        public Integer16(Int16 i)
        {
            value = i;
        }

        private readonly Int16 value;
        public static explicit operator Int16(Integer16 i)
        {
            return i.value;
        }
        public static implicit operator Integer16(Int16 i)
        {
            return new Integer16(i);
        }
        public static Integer16 operator +(Integer16 i1, Integer16 i2)
        {
            return new Integer16((Int16)(i1.value + i2.value));
        }
        public static Integer16 operator -(Integer16 i1, Integer16 i2)
        {
            return new Integer16((Int16)(i1.value - i2.value));
        }
        public static Integer16 operator *(Integer16 i1, Integer16 i2)
        {
            return new Integer16((Int16)(i1.value * i2.value));
        }
        public static Integer16 operator /(Integer16 i1, Integer16 i2)
        {
            return new Integer16((Int16)(i1.value / i2.value));
        }
        public static Integer16 operator %(Integer16 i1, Integer16 i2)
        {
            return new Integer16((Int16)(i1.value % i2.value));
        }
        public static bool operator ==(Integer16 i1, Integer16 i2)
        {
            return i1.value == i2.value;
        }
        public static bool operator !=(Integer16 i1, Integer16 i2)
        {
            return i1.value != i2.value;
        }

        public override bool Equals(object obj)
        {
            if (obj is Integer16)
                return this.value == ((Integer16)obj).value;
            return false;
        }
        public override int GetHashCode()
        {
            return value.GetHashCode();
        }
        public override string ToString()
        {
            return value.ToString();
        }

        public override int CompareTo(Integer16 other)
        {
            return value.CompareTo(other.value);
        }

        public override SignTypes Sign
        {
            get
            {
                if (value > 0)
                    return SignTypes.Positive;
                if (value < 0)
                    return SignTypes.Negative;
                return SignTypes.Zero;
            }
        }
    }
}
